#!/usr/bin/env ruby

if ARGV.empty?
  puts "Yanks all of the gems that a user has push access to."
  puts "USAGE: script/yank_user USERNAME"
  exit
end

handle = ARGV.first
puts "Locking user #{handle}..."

ENV["RAILS_ENV"] ||= "production"
require_relative "../config/environment"

user = User.find_by!(handle: handle)

security_user = User.security_user

user.rubygems.each do |rubygem|
  puts "Yanking #{rubygem.name}"
  rubygem.versions.each do |version|
    puts "  #{version}"
    security_user.deletions.create!(version: version) unless version.yanked?
  end
end

puts "Done."
